package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.modles.ArticleDetailsData;
import com.wangtao.firstapp.modles.CommentsListData;

import java.lang.reflect.Type;
import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 评论列表 适配器
 * Created by lanouhn on 16/9/1.
 */
public class CommentsListAdapter extends RecyclerView.Adapter<CommentsListAdapter.ViewHolder> {
    private Context context;
    private CommentsListData commentsListData;

    public CommentsListAdapter(Context context, CommentsListData commentsListData) {
        this.context = context;
        this.commentsListData = commentsListData;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_comments_commentslist, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Picasso.with(context).load(commentsListData.getData().get(position).getUser().getAvatar()).config(Bitmap.Config.RGB_565).into(holder.iv_header_commentslist);
        holder.tv_username_author.setText(commentsListData.getData().get(position).getUser().getNickname());
        holder.tv_datestr.setText(commentsListData.getData().get(position).getDatestr());
        holder.tv_user_comments.setText(commentsListData.getData().get(position).getConent());
        holder.isauthor.setVisibility(View.VISIBLE);
    }

    @Override
    public int getItemCount() {
        return commentsListData.getData().size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private CircleImageView iv_header_commentslist;
        private TextView tv_username_author, tv_datestr, tv_user_comments, isauthor;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_header_commentslist = (CircleImageView) itemView.findViewById(R.id.iv_header_commentslist);
            tv_username_author = (TextView) itemView.findViewById(R.id.tv_username_author);
            tv_datestr = (TextView) itemView.findViewById(R.id.tv_datestr);
            tv_user_comments = (TextView) itemView.findViewById(R.id.tv_user_comments);
            isauthor = (TextView) itemView.findViewById(R.id.isauthor);
        }
    }

}
